﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Krist_em_up.Characters;
using Microsoft.Xna.Framework;
using Krist_em_up.i18n;

namespace Krist_em_up.Interface.Gui
{

    public class PlayerGui
    {
        protected Kris owner;

        protected PlayerHealth health;

        protected SpriteBatch spriteBatch;

        protected SpriteFont font;

        protected Texture2D background, bullet;

        protected Kristemup game;

        public PlayerGui(Kris owner, Kristemup k, SpriteFont f)
        {
            this.owner = owner;
            this.spriteBatch = new SpriteBatch(k.game.GraphicsDevice);
            this.font = f;
            this.background = k.Content.Load<Texture2D>("guiBG");
            this.bullet = k.Content.Load<Texture2D>("bullet2");
            this.game = k;
            this.health = new PlayerHealth(k);
        }

        public void Update(GameTime gameTime)
        {

        }

        public void Draw(SpriteBatch spritebatch)
        {
            spritebatch.Begin();
            spritebatch.Draw(background, new Rectangle(0, 0, game.game.GraphicsDevice.Viewport.Width, game.game.GraphicsDevice.Viewport.Height), Color.White);
            spritebatch.DrawString(font, "LEVEL "+game.level, Vector2.Zero, Color.Red);
            spritebatch.Draw(bullet, new Vector2(10, font.MeasureString("L").Y + bullet.Width+45), null, Color.White, (float)(-MathHelper.PiOver2), Vector2.Zero, 1.5f,
                SpriteEffects.None, 0);
            string ammo = owner.CurrentAmmo >= 0 ? owner.CurrentAmmo.ToString() : "~";
            spritebatch.DrawString(font, "  X " + ammo, new Vector2(10 + bullet.Height, font.MeasureString("L").Y + 25), Color.White);

            spritebatch.DrawString(font, Strings.vies + " : " + owner.Lives.ToString(), new Vector2(game.game.GraphicsDevice.Viewport.Width
                - font.MeasureString(Strings.vies + " : " + owner.Lives.ToString()).X, font.MeasureString("L").Y + 25), Color.Black);
            spritebatch.End();

            health.Draw(spritebatch, (float)owner.Hp / (float)Kris.MAX_HP);

            if (owner.Bonus != null)
            {
                owner.Bonus.DrawGui(spritebatch, new Vector2(0, font.MeasureString("L").Y + 2*bullet.Width+45));
                spritebatch.Begin();
                spritebatch.DrawString(font, (owner.effectTime - game.time + owner.activation).Seconds.ToString() + "."
                    + ((owner.effectTime - game.time + owner.activation).Milliseconds / 100).ToString(),
                    new Vector2(owner.Bonus.getWidth + 30, font.MeasureString("L").Y + 2*bullet.Width + 30), Color.Black);
                spritebatch.End();

            }
        }
    }
}
